package com.example.i_leidian.crypthook;


import android.telephony.SmsManager;


import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;

/**
 * Created by i-leidian on 2017/6/28.
 */

public class Module implements IXposedHookLoadPackage {
    @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
        XposedBridge.log("Loaded app: " + loadPackageParam.packageName);
//        if (!loadPackageParam.packageName.contains("telephony")) {
//            Log.v("HOOK RETURN ", loadPackageParam.packageName);
//            return;
//        }
        try {
            findAndHookMethod("android.telephony.SmsManager", loadPackageParam.classLoader, "sendTextMessage", new XC_MethodHook() {
                protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                    XposedBridge.log("SEND TEXT MESSEGE !");
                }

                protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                    XposedBridge.log("SEND TEXT MESSEGE !");
                }
            });
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
//public class Module implements IXposedHookLoadPackage {
//
//    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
//        XposedBridge.log("Loaded app: " + lpparam.packageName);
//        HookMethod(SmsManager.class, "sendTextMessage", "00000000000000");
//    }
//
//    private void HookMethod(final Class clazz, final String method, final String result) {
//        try {
//            XposedHelpers.findAndHookMethod(clazz, method, new Object[]{new XC_MethodHook() {
//                protected void afterHookedMethod(MethodHookParam param) throws Throwable {
//                    XposedBridge.log("SEND TEXT MESSEGE !");
//                    //param.setResult(result);
//                }
//            }});
//        } catch (Throwable e) {
//            e.printStackTrace();
//        }
//    }
//}
